package com.code.question5.client;

import com.code.question5.impl.GroupTalkServiceImpl;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务端
 */
public class ServerClient {
    public static void main(String[] args) throws IOException {
        //开启服务端，监听端口8888
        ServerSocket ss = new ServerSocket(8888);
        Socket s = null;
        while (true) {
            System.out.println("等待客户端接入");
            s = ss.accept();
            String clientAddress = s.getInetAddress() + ":" + s.getPort();
            System.out.println("客户端" + clientAddress + "连接成功！");
            //对每个接入的客户端各自分配一个线程
            GroupTalkServiceImpl gts = new GroupTalkServiceImpl(s, true);
            new Thread(gts).start();
        }
    }
}
